{php $bootstrap_type = 3;}
{template 'header'}
<link type="text/css" rel="stylesheet" href="../addons/eso_sale/images/style.css">

<div class="head">
    <a href="javascript:history.back();" class="bn pull-left"><i class="fa fa-angle-left"></i></a>
    <span class="title">结算</span>
</div>


<form class="form-horizontal" method="post" role="form" onsubmit='return check()'>
    <input type="hidden" name="goodstype" value="{$goodstype}" />
    <input type="hidden" name="address" value="{$row['id']}" />
    <div class="order-main">
        <h5>收货地址</h5>
        <div id="myaddress">
            {if !empty($row)}
            <div id='address_{$row['id']}' class="shopcart-main img-rounded address_item" style='margin:0;padding:10px;margin-bottom:10px;cursor:pointer' onclick='changeAddress()'>
            <span>{$row['province']} {$row['city']} {$row['area']} {$row['address']} <br/> {$row['realname']}, {$row['mobile']}</span>
              <span style='float:right'>
                  &nbsp;&nbsp;<a href="{php echo $this->mturl('address',array('from'=>'confirm','returnurl'=>urlencode($returnurl)))}">管理收货地址</a></span>
        </div>
        {else}
        <div><button type="button" class="btn btn-danger" onclick="location.href='{php echo $this->mturl('address',array('from'=>'confirm','returnurl'=>urlencode($returnurl)))}'"><i class="icon-plus"></i> 添加修改地址</button></div>
        {/if}
    </div>
    <h5>配送方式</h5>
    <select id='dispatch' name="dispatch" class="form-control">

        {loop $dispatch $d}
        <option value="{$d['id']}" price='{$d['price']}'>{$d['dispatchname']} ({$d['price']}元)</option>
        {/loop}

    </select>
    <h5>订单详情</h5>
    <div class="order-detail">
        <table class="table">
            <thead>
            <tr>
                <th class="name">商品</th>
                <th class="num">数量</th>
                <th class="total">合计</th>
            </tr>
            </thead>
            <tbody>
            {loop $allgoods $item}


            <tr>
                <td class="name"><span  style="float:left;"><a href='{php echo $this->mturl('detail',array('id'=>$item['id']))}'>
                                                                                   {$item['title']}         </a>
                    {if !empty($item['optionname'])}<br/><span style='font-size:12px;color:#666'> {$item['optionname']}</span>{/if}
                               </span></td>
                <td class="num">{$item['total']}{if !empty($item['unit'])}{$item['unit']}{/if}</td>
                <td class="total"><span class='goodsprice'>{$item['totalprice']} 元</span></td>
            </tr>
            {/loop}
            </tbody>
        </table>
        <div class="order-detail-hd"> <span class="pull-right" style="color:#E74C3C;">
                    [合计：<span id='totalprice'>{$totalprice}</span>]</span></div>
        <div style="clear:both;"></div>
    </div>

    <h5>留言</h5>
    <div class="message-box">
        <textarea class="form-control" rows="3" name="remark" placeholder="亲，还用什么能帮助到您吗？就写到这里吧！"></textarea>
    </div>
    <button type="submit" name="submit" value="yes" class="btn btn-success order-submit btn-lg" style="margin-bottom:20px;">提交订单</button>
    <input type="hidden" name="token" value="{$_W['token']}" />
    </div>


    <script src="../addons/eso_sale/recouse/js/zepto.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        Zepto(function($){
            var $nav = $('.global-nav'), $btnLogo = $('.global-nav__operate-wrap');
            //点击箭头，显示隐藏导航
            $btnLogo.on('click',function(){
                if($btnLogo.parent().hasClass('global-nav--current')){
                    navHide();
                }else{
                    navShow();
                }
            });
            var navShow = function(){
                $nav.addClass('global-nav--current');
            }
            var navHide = function(){
                $nav.removeClass('global-nav--current');
            }

            $(window).on("scroll", function() {
                if($nav.hasClass('global-nav--current')){
                    navHide();
                }
            });
        })
        function get_search_box(){
            try{
                document.getElementById('get_search_box').click();
            }catch(err){
                document.getElementById('keywordfoot').focus();
            }
        }
    </script>




    <script language='javascript'>

        function changeAddress(){
            location.href = '{php echo $this->mturl('address', array('from'=>'confirm','returnurl'=>urlencode($returnurl)))}'
        }
        function check(){
            if((".address_item").length<=0){
                alert("请添加收货地址!");
                return false;
            }
            return true;
        }
        $("#dispatch").change(canculate);
        function canculate(){
            var price = 0;
            $(".goodsprice").each(function(){
                price+=parseFloat($(this).html());
            });
            var dispatchprice = parseFloat($("#dispatch").find("option:selected").attr("price"));
            if(dispatchprice>0){
                $("#totalprice").html(price + dispatchprice + " 元 (含运费"+dispatchprice + ")");
            }
            else{
                $("#totalprice").html(price + " 元");
            }

        }
        $(function(){
            canculate();
        })
    </script>

    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script type="text/javascript">
        //获取指定cookes函数
        function getCookie(name)
        {
            var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");

            if(arr=document.cookie.match(reg))

                return unescape(arr[2]);
            else
                return null;
        }

        if(navigator.appName == 'Microsoft Internet Explorer'){
            if(navigator.userAgent.indexOf("MSIE 5.0")>0 || navigator.userAgent.indexOf("MSIE 6.0")>0 || navigator.userAgent.indexOf("MSIE 7.0")>0) {
                alert('您使用的 IE 浏览器版本过低, 推荐使用 Chrome 浏览器或 IE8 及以上版本浏览器.');
            }
        }

        // jssdk config 对象
        jssdkconfig = {php echo json_encode($_W['account']['jssdkconfig']);} || {};
        // 是否启用调试
        jssdkconfig.debug = false;
        //
        jssdkconfig.jsApiList = [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onRecordEnd',
            'playVoice',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ];

        var wxData = {
            //"appId": "{$_W['account']['key']}",
            "imgUrl" : '{$_W['siteroot']}/source/modules/eso_sale/icon.jpg',
            "link" : '{php echo $_W['siteroot']."app/".$this->mturl('list',array('id'=>$id))}&mid='+getCookie("mid"),
            "desc" : '看你能捞多少佣金',
            "title" : '{$_W['account']['name']}'
        };

        wx.config(jssdkconfig);
        wx.ready(function () {
            wx.onMenuShareAppMessage(wxData);
            wx.onMenuShareTimeline(wxData);
            wx.onMenuShareQQ(wxData);
            wx.onMenuShareWeibo(wxData);
        });
    </script>
</form>
</body>
</html>